#include "WProgram.h"
#include "led_effects.h"

LED_Effects::LED_Effects(int redPin, int greenPin, int bluePin)
{
  
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  _redPin = redPin;
  _greenPin = greenPin;
  _bluePin = bluePin;

}

// quickly set LED states
void LED_Effects::_setLEDs(int r, int g, int b)
{
  digitalWrite(_redPin, r);
  digitalWrite(_greenPin, g);
  digitalWrite(_bluePin, b);
}


// reset internal stuff
void LED_Effects::_reset()
{
	_at = 1;
	_setLEDs(LOW, LOW, LOW);
}


// downStep - make three LEDs blink one at a time in sequence, moving red->green->blue
void LED_Effects::downStep()
{
  
  switch (_at)
  {
    
    case 1:
      _setLEDs(HIGH, LOW, LOW);
      break;
    
    case 2:
      _setLEDs(LOW, HIGH, LOW);
      break;
    
    case 3:
      _setLEDs(LOW, LOW, HIGH);
      _at = 0;
      break;
  }
  
  _at++;
  
}

// upStep - make three LEDs blink one at a time in reverse sequence, movine blue->green->red
void LED_Effects::upStep()
{
  
  switch (_at)
  {
    
    case 1:
      _setLEDs(LOW, LOW, HIGH);
      break;
    
    case 2:
      _setLEDs(LOW, HIGH, LOW);
      break;
    
    case 3:
      _setLEDs(HIGH, LOW, LOW);
      _at = 0;
      break;
    
  }
  
  _at++;
  
}


// downUp - blink three LEDs in alternating sequence
void LED_Effects::downUp()
{
  
  switch (_at)
  {
    
    case 1:
    case 5:
      _setLEDs(HIGH, LOW, LOW);
      _at = 1;
      break;
    
    case 2:
    case 4:
      _setLEDs(LOW, HIGH, LOW);
      break;
    
    case 3:
      _setLEDs(LOW, LOW, HIGH);
      break;   
  }
  
  _at++;
  
}
  

// allBlink - blink all three LEDs at once
void LED_Effects::allBlink()
{

  switch (_at)
  {
    
    case 0:
      _setLEDs(LOW, LOW, LOW);
      _at = 1;
      break;
      
    case 1:
      _setLEDs(HIGH, HIGH, HIGH);
      _at = 0;
      break;
    
  }
  
}


// scroll - scroll three LEDs in sequence, both on and off
void LED_Effects::scroll()
{
  
  switch (_at)
  {
    
    case 1:
      _setLEDs(HIGH, LOW, LOW);
      _at = 1;
      break;
    
    case 2:
      _setLEDs(HIGH, HIGH, LOW);
      break;
    
    case 3:
      _setLEDs(HIGH, HIGH, HIGH);
      break;
    
    case 4:
      _setLEDs(LOW, HIGH, HIGH);
      break;
    
    case 5:
      _setLEDs(LOW, LOW, HIGH);
      break;
    
    case 6:
      _setLEDs(LOW, LOW, LOW);
      _at = 0;
      break;
    
  }
  
  _at++;
  
}


// bounce - light all three LEDs at once in sequence, then reverse
void LED_Effects::bounce()
{

  switch (_at)
  {
    
    case 1:
    case 5:
      _setLEDs(HIGH, LOW, LOW);
      break;
      
    case 2:
    case 4:
      _setLEDs(HIGH, HIGH, LOW);
      break;
    
    case 3:
      _setLEDs(HIGH, HIGH, HIGH);
      break;
    
    case 6:
      _setLEDs(LOW, LOW, LOW);
      _at = 0;
      break;
    
  }
  
  _at++;
  
}

void LED_Effects::spring()
{
	
	switch (_at)
	{
		
		case 1:
		case 12:
			_setLEDs(HIGH, LOW, LOW);
			break;
			
		case 2:
		case 11:
			_setLEDs(HIGH, HIGH, LOW);
			break;
			
		case 3:
		case 9:
			_setLEDs(HIGH, HIGH, HIGH);
			break;
			
		case 4:
		case 8:
			_setLEDs(LOW, HIGH, HIGH);
			break;
			
		case 5:
		case 7:
			_setLEDs(LOW, LOW, HIGH);
			break;
			
		case 6:
			_setLEDs(LOW, LOW, LOW);
			break;
			
		case 13:
			_setLEDs(LOW, LOW, LOW);
			_at = 1;
			break;
		
	}
	
	_at++;
	
}
